﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using System.Data;

namespace radnaVerzija
{
    public partial class DAL
    {
        private string host, db, user, password;
        private static MySqlConnection konekcija = null;

        private static DAL instanca = null;
        public static DAL Instanca
        {
            get
            {
                if (null == instanca)
                    return instanca = new DAL();
                else return instanca;
            }
        }
        
        private DAL() { }
        ~DAL() { terminirajKonekciju(); }

        public DAOFactory getDAO
        {
            get
            {
                return DAOFactory.Instanca;
            }
        }

        public void kreirajKonekciju(string host, string db, string user, string password)
        {
            if (konekcija != null) return;
            string konekcijaString = "server=localhost;user=" + user + ";pwd=" + password + ";database=" + db;
            konekcija = new MySqlConnection(konekcijaString);

            try
            {
                konekcija.Open();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void terminirajKonekciju()
        {
            try
            {
                if (konekcija != null)
                    konekcija.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
